package  
{
	import net.flashpunk.Entity;
	import net.flashpunk.graphics.Image;
	import net.flashpunk.masks.Pixelmask;
	import net.flashpunk.FP;

	public class Bullet extends Entity
	{
		[Embed(source = '/img/bullet1.png')] private const IMG1:Class;
		[Embed(source = '/img/bullet2.png')] private const IMG2:Class;
		[Embed(source = '/img/bullet3.png')] private const IMG3:Class;
		[Embed(source = '/img/bullet4.png')] private const IMG4:Class;
		
		private var img:Image;
		
		private var speed:Number=7;
		private var dirX:Number;
		private var dirY:Number
		
		public function Bullet(px:Number, py:Number, dx:Number,dy:Number) 
		{
			
			if (dx == 1)
			{
				img = new Image(IMG4);
				mask = new Pixelmask(IMG4);
			}
			else if (dx == -1)
			{
				img= new Image(IMG3);
				mask = new Pixelmask(IMG3);
			}
			else if (dy == 1)
			{
				img = new Image(IMG2);
				mask = new Pixelmask(IMG2);
			}
			else if (dy == -1)
			{
				img = new Image(IMG1);
				mask = new Pixelmask(IMG1);
			}
			
			img.scale = 2;
			graphic = img;
			type = "Bullet";
				
			dirX = dx;
			dirY = dy;
			
			x = px;
			y = py;
			
		}
		
		
		override public function update():void
		{
			if (outScreen())
			{	
				FP.world.add(new ExplosionSmall(x-10, y-10));
				FP.world.remove(this);
			}
			
			if ( collide("Wall", x, y))
			{
				FP.world.remove(collide("Wall", x, y));
				FP.world.add(new ExplosionSmall(x-20, y-30));
				FP.world.remove(this);
					
			}
			
			
			x += speed * dirX;
			y += speed * dirY;
		
			
		}
		
		public function outScreen():Boolean
		{
			if ((x+speed * dirX) > FP.screen.width-97-4 || (x+speed * dirX) <45)
				return true;
			if ((y+speed * dirY) > 582-4|| (y+speed * dirY) < 18)
				return true;
			
				return false;
				
			
		}
		
	}

}